<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>待办事项列表</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        ul {
            list-style: none;
            padding: 0;
        }
        li {
            margin: 10px 0;
        }
    </style>
</head>
<body>

<div id="app">
    <h1>待办事项列表</h1>
    <input type="text" v-model="newTask" @keyup.enter="addTask" placeholder="添加新任务" />
    <ul>
        <li v-for="(task, index) in tasks" :key="index">
            {{ task }}
            <button @click="removeTask(index)">删除</button>
        </li>
    </ul>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            newTask: '',
            tasks: []
        },
        methods: {
            addTask() {
                if (this.newTask.trim()) {
                    this.tasks.push(this.newTask);
                    this.newTask = ''; // 清空输入框
                }
            },
            removeTask(index) {
                this.tasks.splice(index, 1); // 删除任务
            }
        }
    });
</script>

</body>
</html>